﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace HeritageAcademy.Models.DataModels
{
    /// <summary>
    /// Users class.
    /// </summary>
    [Serializable]
    [DesignerCategory(@"code")]
    [XmlType(AnonymousType = true)]
    [XmlRoot(Namespace = "", IsNullable = false)]
    public sealed class Users : INotifyPropertyChanged
    {
        private ObservableCollection<User> user = new ObservableCollection<User>();

        /// <summary>
        /// User.
        /// </summary>
        [XmlElement("User", Form = XmlSchemaForm.Unqualified)]
        public ObservableCollection<User> User
        {
            get { return user; }
            set
            {
                user = value;
                OnPropertyChanged("User");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        /// Property changed event handler.
        /// </summary>
        /// <param name="propertyName">Property name string</param>
        private void OnPropertyChanged(string propertyName)
        {
            Debug.Assert(GetType().GetProperty(propertyName) != null);
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <summary>
    /// User class.
    /// </summary>
    [Serializable]
    [DesignerCategory(@"code")]
    [XmlType(AnonymousType = true)]
    public sealed class User : INotifyPropertyChanged
    {
        private string familyName;
        private string icon;
        private string id;
        private string active;
        private string login;
        private string name;
        private string password;
        private string role;

        /// <summary>
        /// User id string.
        /// </summary>
        [XmlAttribute]
        public string Id
        {
            get { return id; }
            set
            {
                id = value;
                OnPropertyChanged("Id");
            }
        }

        /// <summary>
        /// User id string.
        /// </summary>
        [XmlAttribute]
        public string Active
        {
            get { return active; }
            set
            {
                active = value;
                OnPropertyChanged("Active");
            }
        }

        /// <summary>
        /// User login string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string Login
        {
            get { return login; }
            set
            {
                login = value;
                OnPropertyChanged("Login");
            }
        }

        /// <summary>
        /// User first name string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

        /// <summary>
        /// User family name string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string FamilyName
        {
            get { return familyName; }
            set
            {
                familyName = value;
                OnPropertyChanged("FamilyName");
            }
        }

        /// <summary>
        /// User role string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string Role
        {
            get { return role; }
            set
            {
                role = value;
                OnPropertyChanged("Role");
            }
        }

        /// <summary>
        /// User password string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string Password
        {
            get { return password; }
            set
            {
                password = value;
                OnPropertyChanged("Password");
            }
        }

        /// <summary>
        /// User icon path string.
        /// </summary>
        [XmlElement(Form = XmlSchemaForm.Unqualified)]
        public string Icon
        {
            get { return icon; }
            set
            {
                icon = value;
                OnPropertyChanged("Icon");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        /// Property changed event handler.
        /// </summary>
        /// <param name="propertyName">Property name string</param>
        private void OnPropertyChanged(string propertyName)
        {
            Debug.Assert(GetType().GetProperty(propertyName) != null);
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}